package com.powazi.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

import com.powazi.logging.service.LogService;

/**
 * Service Aspect.Using SpringAOP.
 * 
 * @author vivo
 * @date 2007-12-24
 * 
 */
@Aspect
public class ServiceAspect {

	/**
	 * ums service
	 */
	@Pointcut("execution(public * com.powazi.ums..service.*.*(..))")
	public void umsServicePointcut() {
	}

	/**
	 * logging service
	 */
	@Pointcut("execution(public * com.powazi.logging.service.*.*(..))")
	public void logServicePointcut() {
	}

	/**
	 * All service
	 */
	@Pointcut("com.powazi.aop.ServiceAspect.umsServicePointcut() "
	        + "|| com.powazi.aop.ServiceAspect.logServicePointcut()")
	public void allServicePointcut() {

	}

	/**
	 * service aspect
	 */
//	@Before("com.powazi.aop.ServiceAspect.umsServicePointcut()")
	@Before("com.powazi.aop.ServiceAspect.allServicePointcut()")
	public void beforeUMSServices() {
		System.out.println("AOP : I run before services that I log something..");
	}

	/**
	 * for test delete later
	 */
	@Around("com.powazi.aop.ServiceAspect.allServicePointcut()")
	public void aroundUMSServices(ProceedingJoinPoint pjpp) {
		System.out.println("AOP : I run around services that I log something..");
	}

	/*
	 * ACTION
	 */
	protected LogService logService;

	public LogService getLogService() {
		return logService;
	}

	public void setLogService(LogService logService) {
		this.logService = logService;
	}

	//
	// @AfterReturning(pointcut = "abcPointcut()", returning = "returnValue")
	// public void afterReturning(Object returnValue) throws Exception {
	// System.out.println("afterPropertiesSet");
	//
	// }
	//
	// @AfterThrowing(pointcut = "abcPointcut()", throwing = "ex")
	// public void afterThrowing(Throwable ex) throws Exception {
	// System.out.println("afterPropertiesSet");
	// }
	//
	// @After("abcPointcut()")
	// public void after(Throwable ex) throws Exception {
	// System.out.println("afterPropertiesSet");
	// }
	//
	// @Around("abcPointcut()")
	// public void around(ProceedingJoinPoint pjp) throws Exception {
	// try {
	// pjp.proceed();
	// } catch (Throwable e) {
	// e.printStackTrace();
	// }
	// System.out.println("afterPropertiesSet");
	// }

}
